﻿/// <summary>
/// 功能描述    ：PagedList  
/// 创 建 者    ：txb
/// 创建日期    ：2019/1/14 18:02:05 
/// 最后修改者  ：txb
/// 最后修改日期：2019/1/14 18:02:05 
/// </summary>
/// 
namespace AutoTest.Framework.Pager
{
    /// <summary>
    /// 分页列表对象
    /// </summary>
    /// <remarks>
    /// 
    /// </remarks>
    /// <param name="pageIndex"></param>
    /// <param name="pagesize"></param>
    public class PagedList(int pageIndex, int pagesize) : IPagedList
    {
        private int _pageIndex = pageIndex;
        /// <summary>
        /// 当前页码
        /// </summary>
        public int PageIndex { get { return _pageIndex < 1 ? 1 : _pageIndex; } set { _pageIndex = value < 1 ? 1 : value; } }

        private int _pagesize = pagesize;
        /// <summary>
        /// 每页大小
        /// </summary>
        public int PageSize { get { return _pagesize < 1 ? 20 : _pagesize; } set { _pagesize = value < 1 ? 20 : value; } }
        /// <summary>
        /// 总记录数
        /// </summary>
        public int RecordCount { get; set; } = 0;

        /// <summary>
        /// 页数
        /// </summary>
        public int PageCount
        {
            get
            {
                if (PageSize > 0) return (int)(Math.Ceiling(RecordCount * 1.0 / PageSize));
                return 0;
            }
        }
    }

    /// <summary>
    /// 泛型
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public class PagedList<T> : PagedList, IPagedList<T>
    {
        /// <summary>
        /// 无参构造函数
        /// </summary>
        public PagedList() : base(1, 20)
        {

        }

        /// <summary>
        /// 带参构造函数
        /// </summary>
        /// <param name="page"></param>
        /// <param name="pagesize"></param>
        public PagedList(int page, int pagesize) : base(page, pagesize)
        {

        }
        /// <summary>
        /// 分页列表
        /// </summary>
        public List<T> ItemList { get; set; } = [];
    }
}
